{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8e2c3134-2979-4780-bc0b-f08ea57587f7",
   "metadata": {},
   "source": [
    "- https://myapollo.com.tw/blog/langchain-tutorial-agent/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b7fd7cc6-6719-40a6-b58c-df7150ecce1a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-21T15:06:51.444072Z",
     "iopub.status.busy": "2024-10-21T15:06:51.443457Z",
     "iopub.status.idle": "2024-10-21T15:06:51.527615Z",
     "shell.execute_reply": "2024-10-21T15:06:51.525909Z",
     "shell.execute_reply.started": "2024-10-21T15:06:51.444015Z"
    }
   },
   "outputs": [],
   "source": [
    "from rich.pretty import pprint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a022e734-c24f-4625-b2aa-8a80e1adf0e0",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-21T15:06:53.437535Z",
     "iopub.status.busy": "2024-10-21T15:06:53.437098Z",
     "iopub.status.idle": "2024-10-21T15:06:55.621415Z",
     "shell.execute_reply": "2024-10-21T15:06:55.620053Z",
     "shell.execute_reply.started": "2024-10-21T15:06:53.437501Z"
    }
   },
   "outputs": [],
   "source": [
    "import requests\n",
    "import os\n",
    "from langchain_openai import ChatOpenAI\n",
    "from langchain_core.prompts import ChatPromptTemplate\n",
    "from langchain_core.prompts import MessagesPlaceholder\n",
    "from langchain.agents.format_scratchpad.openai_tools import (\n",
    "    format_to_openai_tool_messages,\n",
    ")\n",
    "from langchain.agents.output_parsers.openai_tools import OpenAIToolsAgentOutputParser\n",
    "from langchain.agents import tool\n",
    "from langchain.agents import AgentExecutor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "eb30ed42-4685-40d5-8b0c-e1d4aab0add5",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-21T15:06:56.112604Z",
     "iopub.status.busy": "2024-10-21T15:06:56.112192Z",
     "iopub.status.idle": "2024-10-21T15:06:56.243409Z",
     "shell.execute_reply": "2024-10-21T15:06:56.241478Z",
     "shell.execute_reply.started": "2024-10-21T15:06:56.112580Z"
    }
   },
   "outputs": [],
   "source": [
    "from dotenv import load_dotenv\n",
    "assert load_dotenv()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d5d149f1-6e24-4c3e-b5b6-5c4cb39f7099",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-10-21T15:07:04.591450Z",
     "iopub.status.busy": "2024-10-21T15:07:04.590807Z",
     "iopub.status.idle": "2024-10-21T15:07:04.601382Z",
     "shell.execute_reply": "2024-10-21T15:07:04.599041Z",
     "shell.execute_reply.started": "2024-10-21T15:07:04.591396Z"
    }
   },
   "outputs": [],
   "source": [
    "os.environ[\"LANGCHAIN_PROJECT\"] = \"1021\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9d65444b-a31d-4c36-8c77-a2cf9ffab21e",
   "metadata": {},
   "source": [
    "### create_react_agent"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b6fe393f-3412-4542-ae35-6ead63d33c00",
   "metadata": {},
   "source": [
    "> agent (with tools) employed by `AgentExeutor`\n",
    "- `hub.pull(\"hwchase17/react\")`\n",
    "- `create_react_agent(llm, tools, prompt)`\n",
    "    - `intermediate_steps: List[Tuple[AgentAction, str]]`\n",
    "- 该函数的源码非常清晰而简单；\n",
    "    \n",
    "    ```\n",
    "    prompt = prompt.partial(\n",
    "        tools=tools_renderer(list(tools)),\n",
    "        tool_names=\", \".join([t.name for t in tools]),\n",
    "    )\n",
    "    \n",
    "    if stop_sequence:\n",
    "        stop = [\"\\nObservation\"] if stop_sequence is True else stop_sequence\n",
    "        llm_with_stop = llm.bind(stop=stop)\n",
    "    else:\n",
    "        llm_with_stop = llm\n",
    "    \n",
    "    output_parser = output_parser or ReActSingleInputOutputParser()\n",
    "    \n",
    "    \n",
    "    agent = (\n",
    "        RunnablePassthrough.assign(\n",
    "            agent_scratchpad=lambda x: format_log_to_str(x[\"intermediate_steps\"]),\n",
    "        )\n",
    "        | prompt\n",
    "        | llm_with_stop\n",
    "        | output_parser\n",
    "    )\n",
    "    \n",
    "    return agent\n",
    "    ```\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "09903bb4-68d3-4016-8fbe-d76ed477a666",
   "metadata": {},
   "source": [
    "#### `format_log_to_str`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5b778009-1f8a-436f-8f3f-8f47a1bf1afa",
   "metadata": {},
   "source": [
    "```\n",
    "def format_log_to_str(\n",
    "    intermediate_steps: List[Tuple[AgentAction, str]],\n",
    "    observation_prefix: str = \"Observation: \",\n",
    "    llm_prefix: str = \"Thought: \",\n",
    ") -> str:\n",
    "    \"\"\"Construct the scratchpad that lets the agent continue its thought process.\n",
    "\n",
    "    Args:\n",
    "        intermediate_steps: List of tuples of AgentAction and observation strings.\n",
    "        observation_prefix: Prefix to append the observation with.\n",
    "             Defaults to \"Observation: \".\n",
    "        llm_prefix: Prefix to append the llm call with.\n",
    "                Defaults to \"Thought: \".\n",
    "\n",
    "    Returns:\n",
    "        str: The scratchpad.\n",
    "    \"\"\"\n",
    "\n",
    "    thoughts = \"\"\n",
    "    for action, observation in intermediate_steps:\n",
    "        thoughts += action.log\n",
    "        thoughts += f\"\\n{observation_prefix}{observation}\\n{llm_prefix}\"\n",
    "    return thoughts\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "797aa660-c7c9-47ba-b8ab-35d4966993e9",
   "metadata": {},
   "source": [
    "### AgentExecutor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "35ada6a3-daf5-4d3c-b145-33086b7bbc66",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-09-24T13:25:30.224217Z",
     "iopub.status.busy": "2024-09-24T13:25:30.223618Z",
     "iopub.status.idle": "2024-09-24T13:25:30.254777Z",
     "shell.execute_reply": "2024-09-24T13:25:30.253140Z",
     "shell.execute_reply.started": "2024-09-24T13:25:30.224162Z"
    }
   },
   "outputs": [],
   "source": [
    "@tool\n",
    "def check_site_alive(site: str) -> bool:\n",
    "    \"\"\"Check a site is alive or not.\"\"\"\n",
    "    try:\n",
    "        resp = requests.get(f'https://{site}')\n",
    "        resp.raise_for_status()\n",
    "        return True\n",
    "    except Exception:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "2ca588b6-f039-4105-83d0-08b61809ea79",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-09-24T13:25:31.742335Z",
     "iopub.status.busy": "2024-09-24T13:25:31.741771Z",
     "iopub.status.idle": "2024-09-24T13:25:31.846286Z",
     "shell.execute_reply": "2024-09-24T13:25:31.845095Z",
     "shell.execute_reply.started": "2024-09-24T13:25:31.742286Z"
    }
   },
   "outputs": [],
   "source": [
    "tools = [check_site_alive, ]\n",
    "\n",
    "\n",
    "llm = ChatOpenAI(model=\"gpt-3.5-turbo\", temperature=0)\n",
    "llm_with_tools = llm.bind_tools(tools)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "da5bd9d1-c784-4241-b84f-f50658f1d89d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-09-24T13:25:33.823131Z",
     "iopub.status.busy": "2024-09-24T13:25:33.822748Z",
     "iopub.status.idle": "2024-09-24T13:25:33.833113Z",
     "shell.execute_reply": "2024-09-24T13:25:33.831471Z",
     "shell.execute_reply.started": "2024-09-24T13:25:33.823098Z"
    }
   },
   "outputs": [],
   "source": [
    "prompt = ChatPromptTemplate.from_messages([\n",
    "    (\n",
    "        \"system\",\n",
    "        \"You are very powerful assistant, but don't know current events\",\n",
    "    ),\n",
    "    (\"user\", \"{input}\"),\n",
    "    MessagesPlaceholder(variable_name=\"agent_scratchpad\"),\n",
    "])\n",
    "\n",
    "agent = (\n",
    "    {\n",
    "        \"input\": lambda x: x[\"input\"],\n",
    "        \"agent_scratchpad\": lambda x: format_to_openai_tool_messages(\n",
    "            x[\"intermediate_steps\"]\n",
    "        ),\n",
    "    }\n",
    "    | prompt\n",
    "    | llm_with_tools\n",
    "    | OpenAIToolsAgentOutputParser()\n",
    ")\n",
    "agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f315f638-f65c-4cb4-a8b3-1239fb5fd12d",
   "metadata": {},
   "source": [
    "- `x[\"intermediate_steps\"]` 是由 AgentExecutor 产生并给到 agent 执行的；\n",
    "-  AgentExecutor 把 agent 与 tools 组成 Agent Executor;\n",
    "-  The agent executor is the runtime for an agent. This is what actually calls the agent, executes the actions it chooses, passes the action outputs back to the agent, and repeats. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "795ab505-d892-4475-b75a-06ebf0b460a8",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-09-24T13:35:33.278583Z",
     "iopub.status.busy": "2024-09-24T13:35:33.277453Z",
     "iopub.status.idle": "2024-09-24T13:35:33.329108Z",
     "shell.execute_reply": "2024-09-24T13:35:33.327170Z",
     "shell.execute_reply.started": "2024-09-24T13:35:33.278514Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">AgentExecutor</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">verbose</span>=<span style=\"color: #00ff00; text-decoration-color: #00ff00; font-style: italic\">True</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">agent</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">RunnableMultiActionAgent</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">runnable</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">RunnableSequence</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">first</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">RunnableParallel</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">steps__</span>=<span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'input'</span>: <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">RunnableLambda</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">...</span><span style=\"font-weight: bold\">)</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'agent_scratchpad'</span>: <span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">RunnableLambda</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">...</span><span style=\"font-weight: bold\">)}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"font-weight: bold\">)</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">middle</span>=<span style=\"font-weight: bold\">[</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">ChatPromptTemplate</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_variables</span>=<span style=\"font-weight: bold\">[</span><span style=\"color: #008000; text-decoration-color: #008000\">'agent_scratchpad'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'input'</span><span style=\"font-weight: bold\">]</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_types</span>=<span style=\"font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'agent_scratchpad'</span>: typing.List<span style=\"font-weight: bold\">[</span>typing.Union<span style=\"font-weight: bold\">[</span>langchain_core.messages.ai.AIMessage, langchain_core.messages.human.HumanMessage, langchain_core.messages.chat.ChatMessage, langchain_core.messages.system.SystemMessage, langchain_core.messages.function.FunctionMessage, langchain_core.messages.tool.ToolMessage<span style=\"font-weight: bold\">]]</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"font-weight: bold\">}</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">messages</span>=<span style=\"font-weight: bold\">[</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">SystemMessagePromptTemplate</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">prompt</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">PromptTemplate</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_variables</span>=<span style=\"font-weight: bold\">[]</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">template</span>=<span style=\"color: #008000; text-decoration-color: #008000\">\"You are very powerful assistant, but don't know current events\"</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   │   </span><span style=\"font-weight: bold\">)</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"font-weight: bold\">)</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">HumanMessagePromptTemplate</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">prompt</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">PromptTemplate</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">input_variables</span>=<span style=\"font-weight: bold\">[</span><span style=\"color: #008000; text-decoration-color: #008000\">'input'</span><span style=\"font-weight: bold\">]</span>, <span style=\"color: #808000; text-decoration-color: #808000\">template</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'{input}'</span><span style=\"font-weight: bold\">)</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"font-weight: bold\">)</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">MessagesPlaceholder</span><span style=\"font-weight: bold\">(</span><span style=\"color: #808000; text-decoration-color: #808000\">variable_name</span>=<span style=\"color: #008000; text-decoration-color: #008000\">'agent_scratchpad'</span><span style=\"font-weight: bold\">)</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"font-weight: bold\">]</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"font-weight: bold\">)</span>,\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">RunnableBinding</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">bound</span>=<span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">ChatOpenAI</span><span style=\"font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">client</span>=<span style=\"font-weight: bold\">&lt;</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">openai.resources.chat.completions.Completions</span><span style=\"color: #000000; text-decoration-color: #000000\"> object at </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0x7f5a4c163920</span><span style=\"color: #000000; text-decoration-color: #000000\">&gt;,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">async_client</span><span style=\"color: #000000; text-decoration-color: #000000\">=&lt;openai.resources.chat.completions.AsyncCompletions object at </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0x7f5a4c0f2f90</span><span style=\"color: #000000; text-decoration-color: #000000\">&gt;,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">temperature</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0.0</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">openai_api_key</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">SecretStr</span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">(</span><span style=\"color: #008000; text-decoration-color: #008000\">'**********'</span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">)</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">openai_proxy</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">''</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">)</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">kwargs</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'tools'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">[</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   │   </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #008000; text-decoration-color: #008000\">'function'</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'function'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'name'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #008000; text-decoration-color: #008000\">'check_site_alive'</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'description'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #008000; text-decoration-color: #008000\">'Check a site is alive or not.'</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'parameters'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">{</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #008000; text-decoration-color: #008000\">'object'</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'properties'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'site'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'type'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #008000; text-decoration-color: #008000\">'string'</span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">}}</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   │   │   │   │   </span><span style=\"color: #008000; text-decoration-color: #008000\">'required'</span><span style=\"color: #000000; text-decoration-color: #000000\">: </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">[</span><span style=\"color: #008000; text-decoration-color: #008000\">'site'</span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">]</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   │   │   │   </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   │   │   </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   │   </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   │   </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">]</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   │   </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">}</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   │   </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">)</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">]</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">last</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">OpenAIToolsAgentOutputParser</span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">()</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">)</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">input_keys_arg</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">[]</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">return_keys_arg</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">[]</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">stream_runnable</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #00ff00; text-decoration-color: #00ff00; font-style: italic\">True</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">)</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"color: #808000; text-decoration-color: #808000\">tools</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">[</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">StructuredTool</span><span style=\"color: #000000; text-decoration-color: #000000; font-weight: bold\">(</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">name</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'check_site_alive'</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">description</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">'Check a site is alive or not.'</span><span style=\"color: #000000; text-decoration-color: #000000\">,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">args_schema</span><span style=\"color: #000000; text-decoration-color: #000000\">=&lt;class </span><span style=\"color: #008000; text-decoration-color: #008000\">'pydantic.v1.main.check_site_aliveSchema'</span><span style=\"color: #000000; text-decoration-color: #000000\">&gt;,</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   │   </span><span style=\"color: #808000; text-decoration-color: #808000\">func</span><span style=\"color: #000000; text-decoration-color: #000000\">=&lt;function check_site_alive at </span><span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">0x7f5a43f04900</span><span style=\"font-weight: bold\">&gt;</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   │   </span><span style=\"font-weight: bold\">)</span>\n",
       "<span style=\"color: #7fbf7f; text-decoration-color: #7fbf7f\">│   </span><span style=\"font-weight: bold\">]</span>\n",
       "<span style=\"font-weight: bold\">)</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[1;35mAgentExecutor\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[33mverbose\u001b[0m=\u001b[3;92mTrue\u001b[0m,\n",
       "\u001b[2;32m│   \u001b[0m\u001b[33magent\u001b[0m=\u001b[1;35mRunnableMultiActionAgent\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[33mrunnable\u001b[0m=\u001b[1;35mRunnableSequence\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mfirst\u001b[0m=\u001b[1;35mRunnableParallel\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[33msteps__\u001b[0m=\u001b[1m{\u001b[0m\u001b[32m'input'\u001b[0m: \u001b[1;35mRunnableLambda\u001b[0m\u001b[1m(\u001b[0m\u001b[33m...\u001b[0m\u001b[1m)\u001b[0m, \u001b[32m'agent_scratchpad'\u001b[0m: \u001b[1;35mRunnableLambda\u001b[0m\u001b[1m(\u001b[0m\u001b[33m...\u001b[0m\u001b[1m)\u001b[0m\u001b[1m}\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[1m)\u001b[0m,\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mmiddle\u001b[0m=\u001b[1m[\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1;35mChatPromptTemplate\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33minput_variables\u001b[0m=\u001b[1m[\u001b[0m\u001b[32m'agent_scratchpad'\u001b[0m, \u001b[32m'input'\u001b[0m\u001b[1m]\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33minput_types\u001b[0m=\u001b[1m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'agent_scratchpad'\u001b[0m: typing.List\u001b[1m[\u001b[0mtyping.Union\u001b[1m[\u001b[0mlangchain_core.messages.ai.AIMessage, langchain_core.messages.human.HumanMessage, langchain_core.messages.chat.ChatMessage, langchain_core.messages.system.SystemMessage, langchain_core.messages.function.FunctionMessage, langchain_core.messages.tool.ToolMessage\u001b[1m]\u001b[0m\u001b[1m]\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[1m}\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mmessages\u001b[0m=\u001b[1m[\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[1;35mSystemMessagePromptTemplate\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   │   \u001b[0m\u001b[33mprompt\u001b[0m=\u001b[1;35mPromptTemplate\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   │   │   \u001b[0m\u001b[33minput_variables\u001b[0m=\u001b[1m[\u001b[0m\u001b[1m]\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   │   │   │   \u001b[0m\u001b[33mtemplate\u001b[0m=\u001b[32m\"You\u001b[0m\u001b[32m are very powerful assistant, but don't know current events\"\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   │   \u001b[0m\u001b[1m)\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[1m)\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[1;35mHumanMessagePromptTemplate\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   │   \u001b[0m\u001b[33mprompt\u001b[0m=\u001b[1;35mPromptTemplate\u001b[0m\u001b[1m(\u001b[0m\u001b[33minput_variables\u001b[0m=\u001b[1m[\u001b[0m\u001b[32m'input'\u001b[0m\u001b[1m]\u001b[0m, \u001b[33mtemplate\u001b[0m=\u001b[32m'\u001b[0m\u001b[32m{\u001b[0m\u001b[32minput\u001b[0m\u001b[32m}\u001b[0m\u001b[32m'\u001b[0m\u001b[1m)\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[1m)\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[1;35mMessagesPlaceholder\u001b[0m\u001b[1m(\u001b[0m\u001b[33mvariable_name\u001b[0m=\u001b[32m'agent_scratchpad'\u001b[0m\u001b[1m)\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[1m]\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1m)\u001b[0m,\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1;35mRunnableBinding\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mbound\u001b[0m=\u001b[1;35mChatOpenAI\u001b[0m\u001b[1m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[33mclient\u001b[0m=\u001b[1m<\u001b[0m\u001b[1;95mopenai.resources.chat.completions.Completions\u001b[0m\u001b[39m object at \u001b[0m\u001b[1;36m0x7f5a4c163920\u001b[0m\u001b[39m>,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[33masync_client\u001b[0m\u001b[39m=<openai.resources.chat.completions.AsyncCompletions object at \u001b[0m\u001b[1;36m0x7f5a4c0f2f90\u001b[0m\u001b[39m>,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[33mtemperature\u001b[0m\u001b[39m=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;36m.0\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[33mopenai_api_key\u001b[0m\u001b[39m=\u001b[0m\u001b[1;35mSecretStr\u001b[0m\u001b[1;39m(\u001b[0m\u001b[32m'**********'\u001b[0m\u001b[1;39m)\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[33mopenai_proxy\u001b[0m\u001b[39m=\u001b[0m\u001b[32m''\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[1;39m)\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[33mkwargs\u001b[0m\u001b[39m=\u001b[0m\u001b[1;39m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[32m'tools'\u001b[0m\u001b[39m: \u001b[0m\u001b[1;39m[\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   │   \u001b[0m\u001b[1;39m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   │   │   \u001b[0m\u001b[32m'type'\u001b[0m\u001b[39m: \u001b[0m\u001b[32m'function'\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   │   │   \u001b[0m\u001b[32m'function'\u001b[0m\u001b[39m: \u001b[0m\u001b[1;39m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   │   │   │   \u001b[0m\u001b[32m'name'\u001b[0m\u001b[39m: \u001b[0m\u001b[32m'check_site_alive'\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   │   │   │   \u001b[0m\u001b[32m'description'\u001b[0m\u001b[39m: \u001b[0m\u001b[32m'Check a site is alive or not.'\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   │   │   │   \u001b[0m\u001b[32m'parameters'\u001b[0m\u001b[39m: \u001b[0m\u001b[1;39m{\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   │   │   │   │   \u001b[0m\u001b[32m'type'\u001b[0m\u001b[39m: \u001b[0m\u001b[32m'object'\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   │   │   │   │   \u001b[0m\u001b[32m'properties'\u001b[0m\u001b[39m: \u001b[0m\u001b[1;39m{\u001b[0m\u001b[32m'site'\u001b[0m\u001b[39m: \u001b[0m\u001b[1;39m{\u001b[0m\u001b[32m'type'\u001b[0m\u001b[39m: \u001b[0m\u001b[32m'string'\u001b[0m\u001b[1;39m}\u001b[0m\u001b[1;39m}\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   │   │   │   │   \u001b[0m\u001b[32m'required'\u001b[0m\u001b[39m: \u001b[0m\u001b[1;39m[\u001b[0m\u001b[32m'site'\u001b[0m\u001b[1;39m]\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   │   │   │   \u001b[0m\u001b[1;39m}\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   │   │   \u001b[0m\u001b[1;39m}\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   │   \u001b[0m\u001b[1;39m}\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   │   \u001b[0m\u001b[1;39m]\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   │   \u001b[0m\u001b[1;39m}\u001b[0m\n",
       "\u001b[2;32m│   │   │   │   \u001b[0m\u001b[1;39m)\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[1;39m]\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mlast\u001b[0m\u001b[39m=\u001b[0m\u001b[1;35mOpenAIToolsAgentOutputParser\u001b[0m\u001b[1;39m(\u001b[0m\u001b[1;39m)\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1;39m)\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[33minput_keys_arg\u001b[0m\u001b[39m=\u001b[0m\u001b[1;39m[\u001b[0m\u001b[1;39m]\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[33mreturn_keys_arg\u001b[0m\u001b[39m=\u001b[0m\u001b[1;39m[\u001b[0m\u001b[1;39m]\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[33mstream_runnable\u001b[0m\u001b[39m=\u001b[0m\u001b[3;92mTrue\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1;39m)\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[33mtools\u001b[0m\u001b[39m=\u001b[0m\u001b[1;39m[\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1;35mStructuredTool\u001b[0m\u001b[1;39m(\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mname\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'check_site_alive'\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mdescription\u001b[0m\u001b[39m=\u001b[0m\u001b[32m'Check a site is alive or not.'\u001b[0m\u001b[39m,\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33margs_schema\u001b[0m\u001b[39m=<class \u001b[0m\u001b[32m'pydantic.v1.main.check_site_aliveSchema'\u001b[0m\u001b[39m>,\u001b[0m\n",
       "\u001b[2;32m│   │   │   \u001b[0m\u001b[33mfunc\u001b[0m\u001b[39m=<function check_site_alive at \u001b[0m\u001b[1;36m0x7f5a43f04900\u001b[0m\u001b[1m>\u001b[0m\n",
       "\u001b[2;32m│   │   \u001b[0m\u001b[1m)\u001b[0m\n",
       "\u001b[2;32m│   \u001b[0m\u001b[1m]\u001b[0m\n",
       "\u001b[1m)\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pprint(agent_executor)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "ac3d2ca3-dd74-4486-9aae-248ab7191c1f",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-09-24T13:25:41.816136Z",
     "iopub.status.busy": "2024-09-24T13:25:41.815555Z",
     "iopub.status.idle": "2024-09-24T13:25:44.475106Z",
     "shell.execute_reply": "2024-09-24T13:25:44.473153Z",
     "shell.execute_reply.started": "2024-09-24T13:25:41.816084Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `check_site_alive` with `{'site': 'example.com'}`\n",
      "\n",
      "\n",
      "\u001b[0m\u001b[36;1m\u001b[1;3mTrue\u001b[0m\u001b[32;1m\u001b[1;3mYes, example.com is alive.\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "response = agent_executor.invoke({\n",
    "    'input': 'is example.com alive?',\n",
    "})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "3877beb4-3aa7-409d-a7d9-fe8f4819b2fd",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-09-24T13:25:50.457176Z",
     "iopub.status.busy": "2024-09-24T13:25:50.456576Z",
     "iopub.status.idle": "2024-09-24T13:25:50.474799Z",
     "shell.execute_reply": "2024-09-24T13:25:50.472787Z",
     "shell.execute_reply.started": "2024-09-24T13:25:50.457123Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'input': 'is example.com alive?', 'output': 'Yes, example.com is alive.'}"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "275962dc-1b07-4c36-9607-93e2ff791ab7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-09-24T13:35:21.712640Z",
     "iopub.status.busy": "2024-09-24T13:35:21.712212Z",
     "iopub.status.idle": "2024-09-24T13:35:21.728385Z",
     "shell.execute_reply": "2024-09-24T13:35:21.726882Z",
     "shell.execute_reply.started": "2024-09-24T13:35:21.712603Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">{</span><span style=\"color: #008000; text-decoration-color: #008000\">'input'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'is example.com alive?'</span>, <span style=\"color: #008000; text-decoration-color: #008000\">'output'</span>: <span style=\"color: #008000; text-decoration-color: #008000\">'Yes, example.com is alive.'</span><span style=\"font-weight: bold\">}</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[1m{\u001b[0m\u001b[32m'input'\u001b[0m: \u001b[32m'is example.com alive?'\u001b[0m, \u001b[32m'output'\u001b[0m: \u001b[32m'Yes, example.com is alive.'\u001b[0m\u001b[1m}\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pprint(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0a81d19c-c9d1-4552-98af-04caac2b0c93",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "agent",
   "language": "python",
   "name": "agent"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
